// 轮播图区域
var swiper = new Swiper(".swiper-container", {
  spaceBetween: 30,
  centeredSlides: true,
  loop: true,
  autoplay: {
    delay: 5000,
    disableOnInteraction: false,
  },
  pagination: {
    el: ".swiper-pagination",
    bulletElement: "li",
    clickable: true,
  },
  navigation: {
    nextEl: ".swiper-button-next",
    prevEl: ".swiper-button-prev",
  },
});
// 二级导航
$(".dao li").hover(
  function () {
    $("#show-nav").css("backgroundColor", "#fff");
    $(this).children("#second").slideDown(); //缓动
    $("#show-nav a,h1").css("color", "#000");
  },
  function () {
    $("#show-nav").css("backgroundColor", "transparent");
    $(this).children("#second").css("display", "none");
    $("#show-nav a,h1").css("color", "#fff");
  }
);
// 主体区域
$("#main li").hover(
  function () {
    $(this).css("color", "red").siblings(".sj").css("color", "#333");
  },
  function () {
    $(this).css("color", "#333").siblings(".sj").css("color", "red");
  }
);
//秒杀倒计时
getDiff();
setInterval(getDiff, 1000);
// getDiff可以计算现在距离结束的时间
function getDiff() {
  var now = new Date(); // 现在
  var future = new Date("2021/10/1"); //

  // 两个时间距离的毫秒数
  // var difference = future.getTime() - now.getTime();

  // 简写成
  var difference = future - now; //单位是毫秒

  // 把毫秒换算成秒
  difference = Math.ceil(difference / 1000); //单位是秒

  // 提取天: 1天 = 24*60*60 秒
  var day = parseInt(difference / (24 * 60 * 60));
  // 提前天以后还剩多少秒
  difference = difference - day * 24 * 60 * 60;

  // 提前小时: 1小时 = 60*60 秒
  var hours = Math.floor(difference / 3600);
  // 提前小时以后还剩多少秒
  difference = difference - hours * 3600;

  // 提取分钟: 1分钟 = 60秒
  var minutes = parseInt(difference / 60);

  // 提前分钟以后还剩多少秒
  var seconds = difference - minutes * 60;

  time.innerText = day + "天" + hours + "小时" + minutes + "分" + seconds+"秒";
}
// 点击商品进入详情页
